package com.city.parking;


import com.city.parking.util.KeyboardUtil;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.InputType;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class AddCarActivity extends FragmentActivity implements OnClickListener, 
        OnCheckedChangeListener {
    private RadioGroup mCarType;
    private boolean isBigCar = false;
    private Button mOkBtn;
    private EditText mCarNoEdt;
    private String mCarNo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_add_car);
		TextView titleTv = (TextView) findViewById(R.id.nav_title);
		titleTv.setText("添加车辆");

        ImageView back = (ImageView) findViewById(R.id.nav_ico_back);
        back.setOnClickListener(this);

        ImageView more = (ImageView) findViewById(R.id.nav_ico_more);
        more.setVisibility(View.GONE);

        mCarType = (RadioGroup) findViewById(R.id.car_type_rg);
        mCarType.setOnCheckedChangeListener(this);
        mCarType.check(R.id.car_small_rb);

        mOkBtn = (Button) findViewById(R.id.car_ok_btn);
        mOkBtn.setOnClickListener(this);
        
        mCarNoEdt = (EditText) findViewById(R.id.car_no_edt);
        mCarNoEdt.setInputType(InputType.TYPE_NULL);
        mCarNoEdt.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                new KeyboardUtil(AddCarActivity.this, mCarNoEdt).showKeyboard();
                return false;
            }
        });
    }


    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.nav_ico_back:
            finish();
            break;
        case R.id.car_ok_btn:
            mCarNo = mCarNoEdt.getText().toString();
            if (mCarNo != null && !mCarNo.equals("")) {
                Intent intent = getIntent();
                Bundle data = new Bundle();
                data.putBoolean("big", isBigCar);
                data.putString("car_no", mCarNo);
                intent.putExtras(data);
                setResult(RESULT_OK, intent);
            }
            finish();

            break;

        default:
            break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onCheckedChanged(RadioGroup rg, int idx) {
        // TODO Auto-generated method stub
        switch (idx) {
        case R.id.car_big_rb:
            isBigCar = true;
            break;
        case R.id.car_small_rb:
            isBigCar = false;
            break;
        }
    }
}
